package com.stylefeng.guns.modular.owBackstageMgr.askMgr.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Ask;
import com.stylefeng.guns.modular.owBackstageMgr.askMgr.service.IAskService;

/**
 * 问道我要提问控制器
 *
 * @author fengshuonan
 * @Date 2018-07-01 18:38:20
 */
@Controller
@RequestMapping("/askMgr")
public class AskMgrController extends BaseController {

    private String PREFIX = "/askMgr/ask/";

    @Autowired
    private IAskService askService;

    /**
     * 跳转到问道我要提问首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "ask.html";
    }

    /**
     * 跳转到添加问道我要提问
     */
    @RequestMapping("/ask_add")
    public String askAdd() {
        return PREFIX + "ask_add.html";
    }

    /**
     * 跳转到修改问道我要提问
     */
    @RequestMapping("/ask_update/{askId}")
    public String askUpdate(@PathVariable Integer askId, Model model) {
        Ask ask = askService.selectById(askId);
        model.addAttribute("item",ask);
        LogObjectHolder.me().set(ask);
        return PREFIX + "ask_edit.html";
    }

    /**
     * 获取问道我要提问列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return askService.selectList(null);
    }

    /**
     * 新增问道我要提问
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Ask ask) {
        askService.insert(ask);
        return SUCCESS_TIP;
    }

    /**
     * 删除问道我要提问
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer askId) {
        askService.deleteById(askId);
        return SUCCESS_TIP;
    }

    /**
     * 修改问道我要提问
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Ask ask) {
        askService.updateById(ask);
        return SUCCESS_TIP;
    }

    /**
     * 问道我要提问详情
     */
    @RequestMapping(value = "/detail/{askId}")
    @ResponseBody
    public Object detail(@PathVariable("askId") Integer askId) {
        return askService.selectById(askId);
    }
}
